package demo;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import org.junit.Before;
import org.junit.Test;

import bean.Person;

public class Demo {
	
	
	

	 SqlSessionFactory factory;
		public  void before() throws IOException{
			 InputStream is = Resources.getResourceAsStream("sqlMapconfig.xml");
			 factory = new SqlSessionFactoryBuilder().build(is);
		}
	public void demo(){
		SqlSession session = factory.openSession();
		Person p = session.selectOne("com.personMaper1.selectPerson", 1);
		System.out.println(p);
		session.close();
	}
   public static void main(String[] args) throws IOException {
		Demo d=new Demo();
	    d.before();
		d.demo2();
	}
	
  
   public void demo1(){
		SqlSession session = factory.openSession();
		String p = session.selectOne("com.personMaper1.getName", 1);
		System.out.println(p);
		session.close();
	}
   
   public void demo2(){
		SqlSession session = factory.openSession();
		List<Person> l= session.selectList("com.personMaper1.getList");
		for(Person a:l){
		System.out.println(a);}
		session.close();
	}
   
   
   
}
